package com.lzh.recursion;

/**
 * @author liuzhihao
 * @create 2021-12-29 0:57
 * <p>
 * 递归测试
 */
public class PrintTest {
    public static void main(String[] args) {
        test(3);

        int res = factorial(5);
        System.out.println(" res  = " + res);
    }

    // 打印问题
    public static void test(int n) {
        if (n > 2) {
            test(n - 1);
        }
        System.out.println("n = " + n);
    }

    // 阶乘问题
    public static int factorial (int n) {
        if (n == 1) {
            return 1;
        } else {
            return factorial(n - 1) * n;
        }
    }
}
